<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<th:block th:insert="~{include :: header('群黑名单')}"/>
<th:block th:insert="~{include :: bootstrap-select-css}"/>
<body>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="group-black-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label for="group">groupUid：</label>
                            <input id="group" name="group" placeholder="QQ群号" type="number">
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="searchPre()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.operate.add('',775,200)">
                <i class="fa fa-add"></i> 添加
            </a>
            <a class="btn btn-primary btn-rounded btn-sm" onclick="handoff()">
                <i class="fa fa-add"></i> 切换至白名单
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>

<th:block th:insert="~{include :: footer}"/>
<th:block th:insert="~{include :: bootstrap-select-js}"/>
<script th:inline="javascript">
    const prefix = ctx + "config/bot/black/group";

    $(function () {
        const options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "群黑名单",
            queryParams: queryParams,
            sortOrder: "desc",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            columns: [
                {
                    field: 'state',
                    radio: true
                },
                {
                    field: 'groupUid',
                    title: '群号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.msgId !== 0) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(' + row.id + ',' + 775 + ',' + 200 + ')"><i class="fa fa-edit"></i>修改</a> ');
                            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(' + row.id + ')"><i class="fa fa-trash"></i>删除</a>');
                            return actions.join('');
                        }
                    }
                }]
        };
        $.table.init(options);
    });

    function handoff() {
        $.operate.post(prefix + "/handoff", "", function () {
            parent.location.reload()
        });

    }

    function queryParams(params) {
        return $.table.queryParams(params);
    }

    function searchPre() {
        $.table.search('group-black-form', 'bootstrap-table');
    }

    function resetPre() {
        $("#group-black-form")[0].reset();
        $.table.search('group-black-form', 'bootstrap-table');
    }
</script>

</body>
</html>